package com.kit.data.kitopeso.tools;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class Tools {

    public static void hideSoftInputFromWindow(Context context, View focusedView) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (focusedView != null) {
            imm.hideSoftInputFromWindow(focusedView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            imm.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
        }
    }

    public static void showKeyboard(EditText editText) {
        InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            editText.setFocusable(true);
            editText.setFocusableInTouchMode(true);
            editText.requestFocus();
            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
        }
    }

    public static void toCopy(Context context, String textToCopy) {

    }


//    @SuppressLint("AppBundleLocaleChanges")
//    public static void selectLanguage(Context context, String language) {
//
//
//        Resources resources = context.getResources();
//        Configuration configuration = resources.getConfiguration();
//        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
//
//        Locale locale;
//
//        String c_language;
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//            locale = configuration.getLocales().get(0);
//        } else {
//            locale = configuration.locale;
//        }
//        c_language = locale.getLanguage();
//        LogUtil.e("me", language + "<-language->" + c_language);
//
//        switch (language) {
//            case "fr":
//                locale = new Locale("fr");
//                break;
//            case "sw":
//                locale = new Locale("sw");
//                break;
//            default:
//                locale = new Locale("en");
//                break;
//        }
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//            configuration.setLocale(locale);
//            configuration.setLocales(new LocaleList(locale));
//            context = context.createConfigurationContext(configuration);
//        } else {
//            configuration.locale = locale;
//            resources.updateConfiguration(configuration, resources.getDisplayMetrics());
//        }
//        if (!TextUtils.isEmpty(c_language) && !TextUtils.isEmpty(language) && !language.equals(c_language)) {
//            resources.updateConfiguration(configuration, displayMetrics);
//        }
//        SpUtils.save_string(context, SpUtils.KEY_LANGUAGE, language);
//    }

    public static int dp2px(View view, float dpValue) {
        return (int) (dpValue * view.getContext()
                .getResources().getDisplayMetrics().density + 0.5f);
    }

}
